//
//  InIndentDetailViewController.m
//  Globalstone
//
//  Created by 刘建峰 on 16/7/11.
//  Copyright © 2016年 yuf. All rights reserved.
//

#import "InIndentDetailViewController.h"
#import "CheckTheFileViewController.h"
@interface InIndentDetailViewController (){
    UIWebView *openFileWebView;
}
@property (weak, nonatomic) IBOutlet UIView *navView;
@property (weak, nonatomic) IBOutlet UIScrollView *scroView;
@property (weak, nonatomic) IBOutlet UIView *detailOneView;
@property (weak, nonatomic) IBOutlet UIView *detailTwoView;
@property (weak, nonatomic) IBOutlet UILabel *indentNum;
@property (strong, nonatomic) IBOutlet UILabel *PINum;
@property (weak, nonatomic) IBOutlet UILabel *indnetName;
@property (weak, nonatomic) IBOutlet UILabel *indentType;
@property (weak, nonatomic) IBOutlet UILabel *indentAddress;
@property (weak, nonatomic) IBOutlet UILabel *customName;
@property (weak, nonatomic) IBOutlet UILabel *indentWeight;
@property (weak, nonatomic) IBOutlet UILabel *beginAddress;
@property (weak, nonatomic) IBOutlet UILabel *endAddress;
@property (weak, nonatomic) IBOutlet UILabel *goodsConsult;//参考值
@property (weak, nonatomic) IBOutlet UILabel *payType;
@property (weak, nonatomic) IBOutlet UILabel *prepareDate;

//订仓信息
@property (weak, nonatomic) IBOutlet UILabel *transCompanyName;
@property (weak, nonatomic) IBOutlet UILabel *transDate;
@property (weak, nonatomic) IBOutlet UILabel *payCompany;//货代公司
@property (weak, nonatomic) IBOutlet UILabel *transPrice;
@property (weak, nonatomic) IBOutlet UILabel *weight;

@property (strong, nonatomic) NSString *PIUrl;
@property (strong, nonatomic) NSString *weightNoteUrl;
@end

@implementation InIndentDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    _PIUrl = @"";
    _weightNoteUrl = @"";
    [self initViewLayout];
    [self getOrderImportDetail];
}


- (void)initViewLayout{
    [self adaptiveViewLayout:self.view];
    [self adaptiveViewLayout:self.navView];
    [self adaptiveViewLayout:self.scroView];
    [self adaptiveViewLayout:self.detailOneView];
    [self adaptiveViewLayout:self.detailTwoView];
    
    _scroView.contentSize = flexibleSize(CGSizeMake(0, 955), NO);

}

- (IBAction)back:(id)sender {
    [self backBtn];
}

#pragma   mark---- 查看pi附件
- (IBAction)checkPIClick:(UIButton *)sender {
    UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"SupplyChainStoryboard" bundle:nil];
    CheckTheFileViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"CheckTheFile"];
    page.fileURLString = [NSString stringWithFormat:@"%@%@",IP_Address_ImageDownFuJian_Fresh,_PIUrl];
    page.fileInfo = self.PINameLabel.text;
    [[Common getNavigation] pushViewController:page];
}
#pragma   mark---- 查看码单附件
- (IBAction)checkWeightNoteClick:(UIButton *)sender {
}
#pragma mark === 订单基本信息
- (void)getOrderImportDetail{
    NSMutableDictionary  *dic=[NSMutableDictionary dictionary];
    [dic setObject:[Common getLoginInfo][Key_User_userId] forKey:@"museId"];
    [dic setObject:[Common getLoginInfo][Key_User_password] forKey:@"musePwd"];
    [dic setObject:[Common getLoginInfo][Key_User_onlineKey] forKey:@"museOnlineTag"];
    NSString * lan = [InternationalControl userLanguage];
    if ([lan isEqualToString:@"en"]) {
        [dic setObject:@"2" forKey:@"language"];
    }else{
        [dic setObject:@"1" forKey:@"language"];
    }
    [dic setObject:_indentId forKey:@"oimpId"];
    self.shareApi.delegate=self;
    [self.shareApi  requestOperationWithDic:dic withPath:GS_queryOrderImportDetail withHttpType:@"POST" withTag:GS_GS_queryOrderImportDetail];
}



#pragma   mark---- GetADBanner Request Delegate

-(void)fetchDatabaseFinished:(NSMutableDictionary *)database withTag:(NSInteger)tag{
    
    if (tag==GS_GS_queryOrderImportDetail) {
        
        if (  [[database valueForKey:@"flag"] integerValue]!=1 ) {
            
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            
        }else  {
            NSDictionary * dic = database[@"result"][@"ImportMain"];
            if ([database[@"result"][@"PortType"] isEqualToString:@"Import"]) {
                _indentType.text = [NSString stringWithFormat:@"进口"];
            }else{
                _indentType.text = [NSString stringWithFormat:@"%@",database[@"result"][@"PortType"]];
            }
            _PINum.text = [NSString stringWithFormat:@"%@",dic[@"oimaPiNo"]];
            _indnetName.text = [NSString stringWithFormat:@"%@",dic[@"oimaGoodsType"]];
            _customName.text = [NSString stringWithFormat:@"%@",dic[@"oimaName"]];
            _indentNum.text =  [NSString stringWithFormat:@"%@",database[@"result"][@"order"][@"oimpNo"]];
            _indentAddress.text =  [NSString stringWithFormat:@"%@",database[@"result"][@"adress"]];
            _beginAddress.text =[NSString stringWithFormat:@"%@",dic[@"oimaBeginPort"]];
            _endAddress.text =[NSString stringWithFormat:@"%@",dic[@"oimaEndPort"]];
            _indentWeight.text = [NSString stringWithFormat:@"%@",dic[@"oimaGoodsWeight"]];
            _goodsConsult.text = [NSString stringWithFormat:@"%@",dic[@"oimaGoodsInfo"]];
            
            if(![database[@"result"][@"ImportBookboard"] isEqual:[NSNull null]]){
                NSDictionary * transDic =  database[@"result"][@"ImportBookboard"];
                _transCompanyName.text =  [NSString stringWithFormat:@"%@",transDic[@"oiboName"]];
                NSString *oiboDueTime = transDic[@"oiboDueTime"];//截关时间
                _transDate.text =  [NSString stringWithFormat:@"%@",[oiboDueTime substringToIndex:oiboDueTime.length-2]];
                _weight.text =  [NSString stringWithFormat:@"%@",transDic[@"oiboNum"]];
                _transPrice.text = [NSString stringWithFormat:@"%@",transDic[@"oiboPrice"]];
                _payCompany.text = [NSString stringWithFormat:@"%@",transDic[@"oiboForwardFore"]];
            }
            if(![database[@"result"][@"ImportPayment"] isEqual:[NSNull null]]){
                _prepareDate.text = [NSString stringWithFormat:@"%@",database[@"result"][@"ImportPayment"][@"oipaPlanTimeOut"]];
            }
            if(![database[@"result"][@"ImportImage"] isEqual:[NSNull null]]){
                _PINameLabel.text = [NSString stringWithFormat:@"%@",database[@"result"][@"ImportImage"][@"oiimUrl"]];
                _PIUrl = database[@"result"][@"ImportImage"][@"oiimUrl"];
                _weightNoteNameLabel.text = [NSString stringWithFormat:@"%@",database[@"result"][@"ImportImage"][@"oiimBill"]];
                _weightNoteUrl = database[@"result"][@"ImportImage"][@"oiimBill"];
            }
        }
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
